package com.jason.kotlin.gank.ui

import android.graphics.Color
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.jason.kotlin.gank.R
import com.jason.kotlin.gank.model.RollHistoryBean
import com.jason.kotlin.gank.ui.adapter.RollHistoryTodayAdapter
import com.jason.kotlin.gank.viewmodel.RollMoreViewModel
import com.jason.library.common.base.BaseStateActivity
import com.jason.library.common.ext.observe
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration

/**
 * @description: RollHistoryTodayActivity
 *
 * @author ChenBaoyang
 * @date 4/24/21 10:54
 */
class RollHistoryTodayActivity : BaseStateActivity<RollMoreViewModel>() {

    private lateinit var recyclerView: RecyclerView
    private lateinit var refreshLayout: SwipeRefreshLayout

    private lateinit var adapter: RollHistoryTodayAdapter

    override fun bindLiveData() {
        observe(viewModel!!.dataHistoryToday) {
            adapter.setNewData(it as MutableList<RollHistoryBean>?)
        }
    }

    override fun initView() {
        title = "历史上的今天"
        recyclerView = findViewById(R.id.recyclerView)
        refreshLayout = findViewById(R.id.swipeRefreshLayout)
        refreshLayout.isRefreshing = false
        refreshLayout.isEnabled = false


        val linearLayoutManager =
            LinearLayoutManager(
                this,
                LinearLayoutManager.VERTICAL,
                false
            )
        recyclerView.layoutManager = linearLayoutManager
        recyclerView.itemAnimator = DefaultItemAnimator()
        recyclerView.addItemDecoration(
            HorizontalDividerItemDecoration.Builder(this).color(Color.LTGRAY)
                .build()
        )

        adapter = RollHistoryTodayAdapter()
        recyclerView.adapter = adapter
    }

    override fun getPageTarget() = recyclerView

    override fun reload() {
    }

    override fun getLayoutId() = R.layout.common_activity_recycler_view

    override fun onDataInit() {
        viewModel!!.getHistoryToday()
    }

}